package com.shalehe.joke.dao;

import java.util.List;

import javax.jdo.PersistenceManagerFactory;

import org.springframework.orm.jdo.JdoTemplate;

import com.shalehe.joke.entity.TextJoke;

public class TextJokeDaoImplByJdoTemplate implements TextJokeDao {
	
	private JdoTemplate jdoTemplate;

    public void setPersistenceManagerFactory(PersistenceManagerFactory pmf) {
        this.jdoTemplate = new JdoTemplate(pmf);
    }

	public void addOrUpdateTextJoke(TextJoke joke) {
		jdoTemplate.makePersistent(joke);
	}

	public List<TextJoke> findAllTextJoke() {
		List<TextJoke> jokes = (List<TextJoke>) jdoTemplate.find(TextJoke.class);
		return jokes;
	}

	public TextJoke getTextJoke(Long id) {
		return (TextJoke) jdoTemplate.getObjectById(TextJoke.class, id);
	}

	public void removeTextJoke(Long id) {
		jdoTemplate.deletePersistent(getTextJoke(id));
	}

}
